var o = 1, i = 2, a = 3, r = 4, s = 5, l = 6;
cc.Class({
    extends: cc.Component,
    properties: {
        optType: 0,
        _optData: null,
        tingCancelPre: {
            default: null,
            type: cc.Prefab
        },
        nodeFanBg: cc.Node
    },
    onLoad: function () {
        if (Global.roomInfoModel.getPlayModel() == Global.config.playModel.ERRENQUICK) if (this.optType == r && this.nodeFanBg) {
            if (this.labFan = Global.utils.searchComp(this.nodeFanBg, "lab", cc.Label), this.labFan && this._optData) {
                var e = Global.tableModel.getPlayerModel(Global.config.SEAT_DOWN);
                if (e) {
                    var t = e.getTingResult(), n = -1;
                    if (t && t.length > 0) {
                        for (var o = 0; o < t.length; o++) {
                            var i = t[o];
                            if (i && i.length > 0 && i[0] == this._optData) {
                                n = i[1];
                                break;
                            }
                        }
                        -1 != n && (this.labFan.string = n + Global.utils.getUnit(), this.nodeFanBg.active = !0);
                    }
                }
            }
        } else this.optType == l && this.nodeFanBg && (this.labFan = Global.utils.searchComp(this.nodeFanBg, "lab", cc.Label),
            this.nodeFanBg.active = !0);
    },
    start: function () {
    },
    onDestroy: function () {
        Global.notificationCenter.offAll(this);
    },
    bindData: function (e, t, n) {
        this._optData = e, this._tile = t, this._isGrabGangHu = n;
    },
    onClick: function () {
        if (Global.notificationCenter.emit(Global.eventName.MSG_SHOWZHUANGJIATIP, !1), this.optType == o) {
            Global.notificationCenter.emit(Global.eventName.GAME_GUO);
            var e = Global.tableModel.getRoomId(), t = Global.tableModel.getTableId(),
                n = Global.tableModel.getSeatId();
            if (0 == e || 0 == t) return void cc.error("OperationController onClick", "roomId = " + e + " tableId = " + t + " seatId = " + n);
            Global.msgHandler.requestGuo(e, t, n);
        }
        if (this.optType == i) {
            Global.notificationCenter.emit(Global.eventName.GAME_PENG);
            e = Global.tableModel.getRoomId(), t = Global.tableModel.getTableId(), n = Global.tableModel.getSeatId();
            if (0 == e || 0 == t) return void cc.error("OperationController onClick", "roomId = " + e + " tableId = " + t + " seatId = " + n);
            Global.msgHandler.requestPeng(e, t, n, this._optData);
        }
        if (this.optType == a) if (Global.notificationCenter.emit(Global.eventName.GAME_GANG),
        this._optData.length > 1) Global.notificationCenter.emit(Global.eventName.GAME_SHOW_MULTIGANG, this._optData); else {
            e = Global.tableModel.getRoomId(), t = Global.tableModel.getTableId(), n = Global.tableModel.getSeatId();
            if (0 == e || 0 == t) return void cc.error("OperationController onClick", "roomId = " + e + " tableId = " + t + " seatId = " + n);
            Global.msgHandler.requestGang(e, t, n, this._optData[0]);
        }
        if (this.optType == r) {
            Global.notificationCenter.emit(Global.eventName.GAME_HU);
            e = Global.tableModel.getRoomId(), t = Global.tableModel.getTableId(), n = Global.tableModel.getSeatId();
            if (0 == e || 0 == t) return void cc.error("OperationController onClick", "roomId = " + e + " tableId = " + t + " seatId = " + n);
            var c = "win";
            this._isGrabGangHu && (c = "grabHuGang"), Global.msgHandler.requestHu(e, t, n, this._optData, c);
        }
        if (this.optType == s) if (this._optData.length > 1) this.onShowMultiChi(this._optData, this._tile); else {
            Global.notificationCenter.emit(Global.eventName.GAME_CHI);
            e = Global.tableModel.getRoomId(), t = Global.tableModel.getTableId(), n = Global.tableModel.getSeatId();
            if (0 == e || 0 == t) return void cc.error("OperationController onClick", "roomId = " + e + " tableId = " + t + " seatId = " + n);
            Global.msgHandler.requestChi(e, t, n, this._optData[0], this._tile);
        }
        if (this.optType == l) {
            this.Node_operation = this.node.parent, this.operationArr = [];
            for (var d = 0; d < this.Node_operation.children.length; d++) {
                var u = this.Node_operation.children[d];
                this.operationArr.push(u), u.active = !1;
            }
            this.nodeCanecel = cc.instantiate(this.tingCancelPre), this.Node_operation && this.Node_operation.addChild(this.nodeCanecel);
            var h = new cc.Component.EventHandler();
            h.target = this.node, h.component = "OperationController", h.handler = "onTingCancelClick",
                this.nodeCanecel.getComponent(cc.Button).clickEvents.push(h), Global.tableModel.getPlayerModel(Global.config.SEAT_DOWN).setIsTingSelect(1),
                Global.notificationCenter.emit(Global.eventName.GAME_SET_TINGGRAY_STANDTILE, !0);
        }
        Global.notificationCenter.emit(Global.eventName.MSG_SHOWZHUANGJIATIP, !1);
    },
    onTingCancelClick: function () {
        if (this.operationArr && this.operationArr.length > 0) for (var e = 0; e < this.operationArr.length; e++) {
            this.operationArr[e].active = !0;
        }
        this.nodeCanecel && (this.nodeCanecel.destroy(), this.nodeCanecel = null), Global.tableModel.getPlayerModel(Global.config.SEAT_DOWN).setIsTingSelect(0),
            Global.notificationCenter.emit(Global.eventName.GAME_SET_TINGGRAY_STANDTILE, !1);
    },
    onShowMultiChi: function (e, t) {
        this.clearOperation();
        var n = this;
        cc.loader.loadRes("prefabs/nodeMultiGang", function (o, i) {
            var a = cc.instantiate(i);
            if (n.Node_multigang_operation && a) {
                n.Node_multigang_operation.addChild(a, 10), a.setPosition(cc.p(0, -58));
                var r = a.getComponent("MultiGangController");
                r && r.bindData(e, "chi", t);
            }
        });
    },
    clearOperation: function () {
        var e = Global.utils.searchNode(SceneHelper.getCurScene(), "Node_operation");
        e && e.removeAllChildren(), this.Node_multigang_operation = Global.utils.searchNode(SceneHelper.getCurScene(), "Node_multigang_operation"),
        this.Node_multigang_operation && this.Node_multigang_operation.removeAllChildren();
    }
})
